﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Wizard.WizardControl.Helpers
{
    public static class Extensions
    {

        /// <summary>
        /// http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/791963c8-9e20-4e9e-b184-f0e592b943b0
        /// </summary>
        /// <returns>Ex: casedWordHTTPWriter becomes "Cased Word HTTP Writer", HotMomma becomes "Hot Momma"</returns>
        public static string SplitCamelCase( this string str )
        {
            return Regex.Replace( Regex.Replace( str, @"(\P{Ll})(\P{Ll}\p{Ll})", "$1 $2" ), @"(\p{Ll})(\P{Ll})", "$1 $2" );
        }

        /// <remarks>This was written pre-linq</remarks>
        public static string ToDelimitedString( this List<string> list, string separator = ":", bool insertSpaces = false, string delimiter = "" )
        {
            var result = new StringBuilder();
            for ( int i = 0; i < list.Count; i++ )
            {
                string initialStr = list[i];
                var currentString = ( delimiter == string.Empty ) ? initialStr : string.Format( "{1}{0}{1}", initialStr, delimiter );
                if ( i < list.Count - 1 )
                {
                    currentString += separator;
                    if ( insertSpaces )
                    {
                        currentString += ' ';
                    }
                }
                result.Append( currentString );
            }
            return result.ToString();
        }

    }
}
